<!-- 修改打款记录 -->
<template>
  <div>
    <el-dialog
      width="900px"
      class="modify-payment-dialog"
      :append-to-body="true"
      top="6vh"
      title="修改打款记录"
      :visible="$store.state.dialog.modifyPayment"
      @close="close">
      <el-row>
        <el-col :span="24">
          <el-form :model="editFrom" ref="editFrom" label-width="100px" size="mini">
            <el-row>
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" v-model="editFrom.remark"></el-input>
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="相关图像">
                <div class="uploader">
                  <el-upload
                    action="http://fx.api.ypt56.net/api/image"
                    :show-file-list="true"
                    :data="uploadimg"
                    :multiple="false"
                    name="Picture"
                    v-model="editFrom.image"
                    :on-success="handleAvatarSuccess"
                    :on-error="handleAvatarError"
                    :before-upload="beforeAvatarUpload">
                    <img v-if="editFrom.image" :src="editFrom.image" class="avatar">
                    <i v-if="!editFrom.image" class="el-icon-plus avatar-uploader-icon"></i>
                  </el-upload>
                </div>
              </el-form-item>
            </el-row>
          </el-form>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sureModify()" size="mini">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  updateMoneyMaintain
} from '../api/finance'
export default {
  data () {
    return {
      editFrom: {},
      uploadimg: {}
    }
  },
  props: {
    uploadimgData: {
      type: String,
      default: () => {
        return ''
      }
    },
    edit: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  watch: {
    '$store.state.dialog.modifyPayment' (value) {
      if (value) {
        this.uploadimg = JSON.parse(this.uploadimgData)
        this.editFrom = JSON.parse(this.edit)
      }
    }
  },
  methods: {
    close () {
      this.$store.commit('hide_modify_payment_dialog')
    },
    // 添加客户打款维护、船代打款维护
    async sureModify () {
      const res = await updateMoneyMaintain({
        maintainId: this.editFrom.maintainId,
        remark: this.editFrom.remark, // 备注
        image: this.editFrom.image // 图片地址
      })
      if (res.status === 200) {
        this.$notify({
          title: '成功',
          message: res.msg,
          type: 'success'
        })
        this.$parent.getCustomerMoney(1, 15)
        this.close()
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    },
    beforeAvatarUpload (file) {
      this.uploadimg.image = file.name.split('.')[0]
    },
    handleAvatarSuccess (res, file) {
      this.editFrom.image = res.data[0].path
    },
    handleAvatarError (res, file) {
      console.log(res, file, '图片4444444444')
    }
  }
}
</script>

<style scoped lang="less">
.modify-payment-dialog {
  .uploader {
    width: 178px;
    height: 178px;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .uploader:hover {
    border-color: #409EFF;
  }
  .uploader /deep/ .el-upload__input{
    display: none;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
